package com.hrm.controller;


import com.hrm.pojo.Job;
import com.hrm.pojo.dto.JobRequestParam;
import com.hrm.service.JobService;
import com.hrm.utils.entity.Result;
import com.hrm.utils.entity.StatusCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/job")
@Api(tags = "职位管理接口")
public class JobController {

    @Autowired
    private JobService jobService;


    /**
     * 通过id进行查询职位信息
     * @return
     * @throws Exception
     */
    @PostMapping("/findId/{id}")
    @ApiOperation(value = "通过id进行查询职位信息")
    public Result findId(@PathVariable Integer id)throws Exception{
        Result result = jobService.selectJobById(id);
        return result;
    }

    /**
     * 查询所有职位信息
     * @return
     * @throws Exception
     */
    @PostMapping("/findAll")
    @ApiOperation(value = "获取职位列表")
    public Result findAll()throws Exception{
        Result jobList = jobService.selectJobList();
        return jobList;
    }


    /**
     * 分页查询职位信息、查询职位信息
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "分页查询列表功能以及查询功能")
    @PostMapping("/findPage")
    public Result findPage(@RequestBody JobRequestParam jobRequestParam)throws Exception{
        Result jobPageResult = jobService.selectJobListLikeName(jobRequestParam);
        return jobPageResult;
    }

    @ApiOperation(value = "修改职位功能")
    @PostMapping("/edit")
    public Result edit(@RequestBody Job job) throws Exception{
        Boolean flag = jobService.updateJob(job);
        Result result = new Result(flag,flag==true? StatusCode.SUCCESS:StatusCode.ERROR,"操作成功");
        return result;
    }

    @ApiOperation(value = "添加职位功能")
    @PostMapping("/add")
    public Result add(@RequestBody Job job) throws
            Exception {
        Boolean flag = jobService.addJob(job);
        Result result=new Result(flag,flag==true? StatusCode.SUCCESS:StatusCode.ERROR,"操作完成");
        return result;
    }

    @ApiOperation(value = "删除单个职位以及多个职位功能")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "职位ID",required = true,paramType = "query",dataType = "int"),
    })
    @PostMapping("/delete/{ids}")
    public Result delete(@PathVariable Integer[] ids) throws
            Exception {
        Boolean flag = jobService.deleteById(ids);
        Result result=new Result(flag,flag==true?
                StatusCode.SUCCESS:StatusCode.ERROR,"操作完成");
        return result;
    }

}
